package com.tanhua.server.controller;

import com.tanhua.domain.mongo.Video;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("smallVideos")
public class VideoController {
    @Autowired
    private VideoService videoService;
    /**
     * 接口名称：小视频列表
     * 接口路径：GET/smallVideos
     */
    @GetMapping
    public ResponseEntity<Object> videoList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize){
        if (page<0){
            page = 1;
        }
        PageResult pageResult = videoService.videoList(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 接口名称：视频上传
     * 接口路径：POST/smallVideos
     */
    @PostMapping
    public ResponseEntity<Object> saveVideo(String text,
            MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        return videoService.saveVideo(text,videoThumbnail,videoFile);
    }

    /**
     * 接口名称：视频用户关注
     * 接口路径：POST/smallVideos/:uid/userFocus
     */
    @PostMapping("{uid}/userFocus")
    public ResponseEntity<Object> userFocus(@PathVariable("uid") Long followUserId)  {
        return videoService.userFocus(followUserId);
    }

    /**
     * 接口名称：视频用户关注 - 取消
     * 接口路径：POST /smallVideos/:uid/userUnFocus
     */
    @PostMapping("{uid}/userUnFocus")
    public ResponseEntity<Object> userUnFocus(@PathVariable("uid") Long unfollowUserId)  {
        return videoService.userUnFocus(unfollowUserId);
    }

}
